package com.zxl.admin.controller.goods;

import com.github.pagehelper.PageInfo;
import com.zxl.admin.service.GoodsService;
import com.zxl.common.Page;
import com.zxl.common.Result;
import com.zxl.common.model.bo.goods.GoodsAdd;
import com.zxl.common.model.bo.goods.GoodsCgt;
import com.zxl.common.model.query.goods.GoodsListQuery;
import com.zxl.common.model.vo.goods.GoodsListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zxw
 * @date 2023/3/31
 */
@Api(tags = "商品管理")
@RestController
@RequestMapping("/admin/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    private RestTemplate restTemplate;

    @PostMapping("/add")
    @ApiOperation("商品添加")
    public Result add(@Valid @RequestBody GoodsAdd goodsAdd){
        goodsService.addGoods(goodsAdd);
        return Result.success("商品添加成功");
    }

    @GetMapping("/select")
    @ApiOperation("商品列表查询")
    public Result<Page<GoodsListVo>> select(GoodsListQuery goodsListQuery){
        List<GoodsListVo> sysGoodsList = goodsService.selectGoodsList(goodsListQuery);
        Page<GoodsListVo> page = Page.pageInfoConvert(new PageInfo(sysGoodsList));
        return new Result(page);
    }

    @PostMapping("/update")
    @ApiOperation("商品修改")
    public Result update(@Valid @RequestBody GoodsAdd goodsAdd){
        goodsService.updateGoods(goodsAdd);
        return Result.success("商品修改成功");
    }

    @PostMapping("/delete")
    @ApiOperation("商品删除")
    public Result deleteGoods(@RequestParam @ApiParam(value = "商品id") Integer id) {
        goodsService.doDeleteGoods(id);
        return Result.success("删除成功");
    }

    @ApiOperation("修改商品状态")
    @PostMapping("/actions/update_goodsStatus")
    public Result setCGoodsStatus(@RequestParam @ApiParam(value = "商品id") Integer id, @RequestParam @ApiParam(value = "商品状态") Integer status){
        goodsService.doSetCGoodsStatus(id,status);
        return Result.success("商品状态修改成功");
    }


    @ApiOperation("修改商品分类")
    @PutMapping("/actions/update_class_ification")
    public Result classification(@RequestBody GoodsCgt goodsCgt) {
        goodsService.updateGoodsCgt(goodsCgt);
        return Result.success("修改成功");
    }


}
